﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
using DBUtlity;
using System.Data.SqlClient;


namespace DAL
{
    /// <summary>
    /// 管理员数据访问类
    /// </summary>
    public class SysAdminService
    {
        /// <summary>
        /// 根据账号密码从数据库比对
        /// </summary>
        /// <param name="objAdmin"></param>
        /// <returns></returns>
        public SysAdmin AdminLogin(SysAdmin objAdmin)
        {
            string sql = "select AdminName,LoginPwd,StatusId,RoleId from SysAdmins where ";
            sql += "AdminId=@AdminId and LoginPwd=@LoginPwd";
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@AdminId", objAdmin.AdminId),
                new SqlParameter("@LoginPwd",objAdmin.LoginPwd)
            };
            SqlDataReader objReader = SQLHelper.GetReader(sql, param);
            if(objReader.Read())
            {
                objAdmin.AdminName = objReader["AdminName"].ToString();
                objAdmin.RoleId = Convert.ToInt32(objReader["RoleId"]);
                objAdmin.StatusId = Convert.ToInt32(objReader["StatusId"]);
            }
            else
            {
                objAdmin = null;//清空
            }
            objReader.Close();
            return objAdmin;
        }
    }
}
